﻿/*=========================================================================
 * AUTH: Vincent Breton
 * DESC: Game Over Screen
 * REF: Stellar Siege Project 2010
 *=========================================================================*/
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace RisingThreat
{

    class GameOverScreen:Screen
    {
        //set up the title
        SpriteFont titleFont;
        Vector2 titlePos;
        String title = "RISING THREAT";

        SpriteFont menuFont;
        Vector2 menuPos;
        String gameOver = "GAME OVER";
        Boolean firstTimeInMenu = true;


        public GameOverScreen(ContentManager content, EventHandler gameEvent, GraphicsDeviceManager graphics)
            : base(gameEvent)
        {
            String prefix = (graphics.PreferredBackBufferHeight >= 600) ? "" : "low-res_";

            titleFont = content.Load<SpriteFont>("fonts/Cutscene");
            menuFont = content.Load<SpriteFont>("fonts/Cutscene");

//            if (graphics.PreferredBackBufferHeight < 600)
//            {
                titlePos = new Vector2(graphics.GraphicsDevice.Viewport.TitleSafeArea.X + 40,
                    graphics.GraphicsDevice.Viewport.TitleSafeArea.Y + 50);
                menuPos = new Vector2(titlePos.X + 75, titlePos.Y + 70 + titleFont.MeasureString(title).Y);
//            }
//            else
//            {

//                titlePos = new Vector2(40.0f, 60.0f);
//                menuPos = new Vector2(100.0f, 200.0f);
//            }

        }

        public void setFirstTimeInMenu(Boolean bo)
        {
            firstTimeInMenu=bo;
        }

        public override void Update(GameTime gametime)
        {
            KeyboardState keyboardState = Keyboard.GetState();
            GamePadState var = GamePad.GetState(PlayerIndex.One);

                if (firstTimeInMenu && !(keyboardState.IsKeyDown(Keys.Enter) || var.Buttons.A == ButtonState.Pressed) )
                {
                    firstTimeInMenu = false;
                }
                else if (!firstTimeInMenu && (keyboardState.IsKeyDown(Keys.Enter) || (var.Buttons.A == ButtonState.Pressed )))
                {
                    screenEvent.Invoke(this, new EventArgs());
                }


            
            base.Update(gametime);

        }

        public override void Draw(SpriteBatch batch)
        {
            Vector2 currentPosition = menuPos;

            //Draw Title
            batch.DrawString(titleFont, title, titlePos, Color.White);

            batch.DrawString(menuFont, gameOver, currentPosition, Color.Red);
            
            base.Draw(batch);

        }
    }
}
